import axios from "axios";

axios.interceptors.request.use(function(config) {
  let token = localStorage.getItem('token');
  if (token) {
    config.headers.Authorization = token;
  }
  return config;
}, function(error) {
  return Promise.reject(error);
});
// response拦截器
axios.interceptors.response.use(response => {
  return response;
}, error => {
  console.log(error);
});



//通用方法
export const POST = (url, params) => {
  return axios.post(`${url}`, params).then(res => res.data).catch(res => res.data)
};

export const GET = (url, params) => {
  return axios.get(`${url}`, {
    params: params
  }).then(res => res.data)
};

export const PUT = (url, params) => {
  return axios.put(`${url}`, params).then(res => res.data)
};

export const DELETE = (url, params) => {
  return axios.delete(`${url}`, {
    params: params
  }).then(res => res.data)
}

export const PATCH = (url, params) => {
  return axios.patch(`${url}`, params).then(res => res.data)
}


